package visitor

import "fmt"

type CityVisitor struct {
	cities map[string]int
}

func NewCityVisitor() ISaleOrderVisitor {
	return &CityVisitor{
		cities: make(map[string]int,0),
	}
}

func (me *CityVisitor) Visit(it *SaleOrder) {
	n,ok := me.cities[it.City]
	if ok {
		me.cities[it.City] = n + it.Quantity
	} else {
		me.cities[it.City] = it.Quantity
	}
}

func (me *CityVisitor) Report() {
	for k,v := range me.cities {
		fmt.Printf("city=%s, sum=%v\n", k, v)
	}
}
